import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Bike {
    public static void main(String[] args) {
        People ellie = new People("Ellie");
        People mike = new People("Mike");
        People rohan = new People("Rohan");
        People fatma = new People("Fatma");
        List<People> peopleList = new ArrayList<>();
        List list = Arrays.asList(ellie, mike, rohan, fatma);
        peopleList.addAll(list);
        // 确定ellie的颜色为紫色，rohan的颜色为红色或者蓝色
        ellie.color = "purple";
        ArrayList<String> rohanColor = new ArrayList<String>(Arrays.asList("red", "blue"));
        for (String rohanBikeColor : rohanColor
        ) {
            rohan.color = rohanBikeColor;
            //如果rohan的颜色为红色
            if (rohan.color.equals("red")) {
                // fatma的颜色是蓝色或绿色
                ArrayList<String> fatmaColor = new ArrayList<String>(Arrays.asList("green", "blue"));
                for (String fatmaBikeColor : fatmaColor
                ) {
                    fatma.color = fatmaBikeColor;
                    if (fatma.color.equals("green")) {
                        mike.color = "blue";
                    } else {
                        mike.color = "green";
                    }
                    int[] mikeIndexArray = {2, 3};
                    for (int mikeIndex : mikeIndexArray
                    ) {
                        mike.index = mikeIndex;
                        if (mike.index == 2) {
                            ellie.index = 3;
                        } else {
                            ellie.index = 2;
                        }
                        int[] fatmaIndexArray = {1, 4};
                        for (int fatmaIndex : fatmaIndexArray
                        ) {
                            fatma.index = fatmaIndex;
                            if (fatma.index == 4) {
                                rohan.index = 1;
                            } else {
                                rohan.index = 1;
                            }
                            if (judgeConditions(peopleList, fatma)) showAnswer(peopleList);
                        }
                    }
                }
            } else {
                ArrayList<String> fatmaColor = new ArrayList<String>(Arrays.asList("red", "green"));
                for (String fatmaBikeColor : fatmaColor
                ) {
                    fatma.color = fatmaBikeColor;
                    if (fatma.color.equals("red")) {
                        mike.color = "green";
                    } else {
                        mike.color = "blue";
                    }
                    int[] mikeIndexArray = {2, 3};
                    for (int mikeIndex : mikeIndexArray
                    ) {
                        mike.index = mikeIndex;
                        if (mike.index == 2) {
                            ellie.index = 3;
                        } else {
                            ellie.index = 2;
                        }
                        int[] fatmaIndexArray = {1, 4};
                        for (int fatmaIndex : fatmaIndexArray
                        ) {
                            fatma.index = fatmaIndex;
                            if (fatma.index == 4) {
                                rohan.index = 1;
                            } else {
                                rohan.index = 1;
                            }
                            if (judgeConditions(peopleList, fatma)) showAnswer(peopleList);
                        }
                    }
                }
            }
        }
    }


    private static boolean judgeConditions(List<People> peopleList, People fatma) {
        if (getPeopleByColor(peopleList, "blue").index < fatma.index) {
            if (getPeopleByColor(peopleList, "green").index < getPeopleByColor(peopleList, "purple").index) {
                return true;
            }
        }
        return false;
    }

    private static void showAnswer(List<People> peopleList) {
        System.out.println("the 2nd people is: " + getPeopleByIndex(peopleList, 2).name);
    }

    private static People getPeopleByColor(List<People> peopleList, String color) {
        for (People p : peopleList
        ) {
            if (p.color.equals(color)) {
                return p;
            }
        }
        return null;
    }

    private static People getPeopleByIndex(List<People> peopleList, int index) {
        for (People p : peopleList
        ) {
            if (p.index == index) {
                return p;
            }
        }
        return null;
    }
}

enum Color {
    RED("red"), GREEN("green"), BLUE("blue"), PURPLE("purple");

    private final String color;

    private Color(String color) {
        this.color = color;
    }
    @Override
    public String toString() {
        return this.color;
    }
}


